package cn.zebra.dev.product.module.question.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.product.module.question.dao.ProductQuestionReplyDao;
import cn.zebra.dev.product.module.question.entity.ProductQuestionReplyEntity;
import cn.zebra.dev.product.module.question.service.ProductQuestionReplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author HH
 */
@Service
public class ProductQuestionReplyServiceImpl extends ServiceImpl<ProductQuestionReplyDao, ProductQuestionReplyEntity> implements ProductQuestionReplyService {
    @Override
    public PageUtils<ProductQuestionReplyEntity> findPage(Map<String, Object> map) {
        QueryWrapper<ProductQuestionReplyEntity> wrapper = new QueryWrapper<>();
        wrapper.select("id, product_question_id, product_question_reply_content, member_reply_id, member_reply_name, create_time");
        wrapper.apply(map.containsKey("productQuestionId"), "product_question_id = {0}", map.get("productQuestionId"));
        wrapper.orderByDesc("id");
        IPage<ProductQuestionReplyEntity> iPage = this.page(
                new Query<ProductQuestionReplyEntity>(map).getPage(),
                wrapper
        );
        return new PageUtils<>(iPage);
    }

    @Override
    public List<ProductQuestionReplyEntity> findByIds(List<Long> productQuestionIds) {
        QueryWrapper<ProductQuestionReplyEntity> wrapper = new QueryWrapper<>();
        wrapper.in("product_question_id",productQuestionIds);
        wrapper.apply("delete_flag = FALSE");
        return list(wrapper);
    }
}
